package com.mengxuegu.springboot.controller;

import com.mengxuegu.springboot.entities.CardBean;
import com.mengxuegu.springboot.entities.UsersBean;
import com.mengxuegu.springboot.mapper.BankCardMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/card")
@RestController
public class BankCardController {
    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    BankCardMapper bankCardMapper;

    @PostMapping("/getBillByName")
    public Object getBillByName(@RequestBody UsersBean bean){
        logger.info("+++++"+bean.getIname());
        return bankCardMapper.getBillByName(bean.getIname());
    }

    @PostMapping("/getBillNum")
    public Object getBillNum(@RequestBody CardBean cardBean){
        logger.info("查询卡号+++++"+cardBean.getNum());
        return bankCardMapper.getBillNum(cardBean.getNum());
    }

    @PostMapping("/addBankCard")
    public boolean addBankCard(@RequestBody CardBean cardBean){
        //DOTO 查询用户，关联user_id
//        cardBean.setUser_id();

        int i = bankCardMapper.addBankCard(cardBean);
        if(i > 0){
            return true;
        }
        return false;
    }

    @PostMapping("/updateCardByNum")
    public boolean updateCardByNum(@RequestBody CardBean cardBean){

        int i = bankCardMapper.updateCardByNum(cardBean);
        if(i > 0){

            return true;
        }
        return false;
    }


}
